package com.dataextend.controller;

import com.alibaba.fastjson.JSONObject;
import com.dataextend.dto.ResultSegment;
import com.dataextend.entity.RequestTableChannel;
import com.dataextend.service.ReportChannelService;
import com.dataextend.service.ReportKpiService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  KPI报表模块接口
 */
@RestController
@RequestMapping("/v1/Report")
public class ReportKpiController {
    @Autowired
    private ReportKpiService reportKpiService;
    @Autowired
    private ReportChannelService reportChannelService;

    /**
     *  双柱形图/折线图
     * @param dataDate
     * @return
     */
    @RequestMapping(value = "/channel/mainReport", method = RequestMethod.POST)
    public ResultSegment mainReport(@RequestParam(value = "dataDate", required = false) String dataDate){
        JSONObject result = reportChannelService.mainReport(dataDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    /**
     * 渠道表格
     */
    @RequestMapping(value = "/channel/searchTable", method = RequestMethod.POST)
    public ResultSegment searchTable(@RequestBody RequestTableChannel requestTableChannel) {
        JSONObject result = reportChannelService.searchTable(requestTableChannel.getStartDate(),
                requestTableChannel.getEndDate(), requestTableChannel.getChannel());
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    /**
     * 渠道下拉菜单
      * @return
     */
    @RequestMapping(value = "/channel/list", method = RequestMethod.POST)
    public ResultSegment channelList(){
        JSONObject result = reportChannelService.channelList();
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    /**
     * 渠道价值分析
     * @param dataDate
     * @return
     */
    @RequestMapping(value = "/channel/searchTableValue", method = RequestMethod.POST)
    public ResultSegment searchTableValue(@RequestParam(value = "dataDate", required = false) String dataDate){
        JSONObject result = reportChannelService.searchTableValue(dataDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    /**
     * 新增注册用户数
     * @param dataDate
     * @return
     */
    @ApiOperation("新增注册用户数")
    @RequestMapping(value = "/kpi/newRegistNum", method = RequestMethod.POST)
    public ResultSegment newRegistNum(@RequestParam(value = "dataDate", required = false) String dataDate){
        JSONObject result =  reportKpiService.newRegistNum(dataDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
        return new ResultSegment(false,400,"程序异常");
        }
    }

    /**
     * 日活用户数
     * @param dataDate
     * @return
     */
    @ApiOperation("日活用户数")
    @RequestMapping(value = "/kpi/liveUsers", method = RequestMethod.POST)
    public ResultSegment liveUsers(@RequestParam(value = "dataDate", required = false) String dataDate){
        JSONObject result =  reportKpiService.liveUsers(dataDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    /**
     * 付费用户数
     * @param dataDate
     * @return
     */
    @ApiOperation("付费用户数")
    @RequestMapping(value = "/kpi/paidUsers", method = RequestMethod.POST)
    public ResultSegment paidUsers(@RequestParam(value = "dataDate", required = false) String dataDate){
        JSONObject result =  reportKpiService.paidUsers(dataDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    /**
     * 付费订单量
     * @param dataDate
     * @return
     */
    @ApiOperation("付费订单量")
    @RequestMapping(value = "/kpi/paidOrders", method = RequestMethod.POST)
    public ResultSegment paidOrders(@RequestParam(value = "dataDate", required = false) String dataDate){
        JSONObject result =  reportKpiService.paidOrders(dataDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    @ApiOperation("订单金额")
    @RequestMapping(value = "/kpi/orderAmount", method = RequestMethod.POST)
    public ResultSegment orderAmount(@RequestParam(value = "startDate", required = false) String startDate,
                                   @RequestParam(value = "endDate", required = false) String endDate){
        JSONObject result = reportKpiService.orderAmount(startDate, endDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    @ApiOperation("累计用户数")
    @RequestMapping(value = "/kpi/cumulativeUsers", method = RequestMethod.POST)
    public ResultSegment cumulativeUsers(@RequestParam(value = "startDate", required = false) String startDate,
                                   @RequestParam(value = "endDate", required = false) String endDate){
        JSONObject result = reportKpiService.cumulativeUsers(startDate, endDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    @ApiOperation("日活用户渠道分布")
    @RequestMapping(value = "/kpi/userChannelDistribute", method = RequestMethod.POST)
    public ResultSegment userChannelDistribute(@RequestParam(value = "startDate", required = false) String startDate,
                                      @RequestParam(value = "endDate", required = false) String endDate){
        JSONObject result = reportKpiService.userChannelDistribute(startDate, endDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    @ApiOperation("日活用户城市分布")
    @RequestMapping(value = "/kpi/cityDistribute", method = RequestMethod.POST)
    public ResultSegment cityDistribute(@RequestParam(value = "startDate", required = false) String startDate,
                                      @RequestParam(value = "endDate", required = false) String endDate){
        JSONObject result = reportKpiService.cityDistribute(startDate, endDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    @ApiOperation("日活用户平台分布")
    @RequestMapping(value = "/kpi/platformDistribute", method = RequestMethod.POST)
    public ResultSegment platformDistribute(@RequestParam(value = "startDate", required = false) String startDate,
                                      @RequestParam(value = "endDate", required = false) String endDate){
        JSONObject result = reportKpiService.platformDistribute(startDate, endDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }


    @ApiOperation("日活用户新老客分布")
    @RequestMapping(value = "/kpi/newoldlDistribute", method = RequestMethod.POST)
    public ResultSegment newoldlDistribute(@RequestParam(value = "startDate", required = false) String startDate,
                                      @RequestParam(value = "endDate", required = false) String endDate){
        JSONObject result = reportKpiService.newoldlDistribute(startDate, endDate);
        if (result != null){
            return new ResultSegment(true,1,"查询成功", result);
        } else {
            return new ResultSegment(false,400,"程序异常");
        }
    }
}
